<template>
  <div id="add">
    <h1 class="title">修改理赔</h1>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="所属订单">
        <el-select v-model="form.ordersId" placeholder="请选择所属订单">
          <el-option
            :label="item._id"
            :value="item._id"
            v-for="item in insuresorders"
            :key="item._id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请时间">
        <el-col :span="11">
          <el-input
            v-model="form.applyTime"
            placeholder="选择申请日期"
            disabled
          ></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="事故日期">
        <el-date-picker
          type="date"
          placeholder="选择事故日期"
          v-model="form.accidentTim"
          style="width: 100%"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          id="time"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="理赔图片"> </el-form-item>
      <el-upload
        class="avatar-uploader"
        action="http://localhost:3000/images/uploadImages"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
        :before-upload="beforeAvatarUpload"
      >
        <img v-if="imageUrl" :src="imageUrl" class="avatar" />
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>

      <el-form-item>
        <el-button type="primary" @click="cancel()">确认修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions, mapState, mapMutations } = createNamespacedHelpers(
  "salesmansclaims"
);
const {
  mapActions: mapActionss,
  mapState: mapStates,
} = createNamespacedHelpers("insuresorders");
export default {
  created() {
    const isAdmins = JSON.parse(localStorage.getItem("loginUser"));
    this.getMyOrders(isAdmins._id);
    this.getSaleClaims(this.$route.params._id);
  },
  data() {
    return {
      form: {
        ordersId: "",
        applyTime: "",
        accidentTim: "",
        state: 1,
        images: "",
      },
      imageUrl: "",
    };
  },
  watch: {
    claims: {
      handler() {
        if (!this.imageUrl) {
          this.form = this.claims[0];
          this.imageUrl = "http://localhost:3000/images/" + this.form.images;
        }
      },
      deep: true,
    },
  },
  computed: {
    ...mapStates(["insuresorders"]),
    ...mapState(["claims"]),
  },
  methods: {
    ...mapActions(["getSaleClaims", "updataSaleClaims"]),
    ...mapActionss(["getMyOrders"]),

   
    cancel() {
      this.updataSaleClaims({_id:this.$route.params._id,update:this.form});
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },

    handleAvatarSuccess(res, file) {
      this.form.images = res.data[0];
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {},
  },
};
</script>

<style lang="scss" scoped>
.title {
  font-size: 18px;
  font-weight: lighter;
  margin: 10px 0;
}
.el-input {
  width: 200px;
}
.el-form-item__content {
  width: 200px;
}
.avatar-uploader {
  width: 178px;
  margin-left: 100px;
  margin-top: -50px;
  margin-bottom: 30px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.el-upload {
  margin-left: 50px;
  margin-bottom: 40px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.el-form-item {
  width: 300px;
}
</style>